<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>签约网</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../css/style1.css" />
    <link rel="stylesheet" type="text/css" href="../css/lawyer.css" />
    <script type="text/javascript" src="../script/api.js"></script>
    <script type="text/javascript" src="../script/jquery-1.9.1.min.js"></script>
    <script type="text/javascript" src="../script/mobile.js"></script>
    <script type="text/javascript" src="../script/lawyer.js"></script>
        <style>

         .order_list ul li .active_btn .no_btn em{
            display: inline-block;
            padding-left: 0.35rem;
        }
        .order_list ul li .active_btn .no_btn em.tel{
            background: url("../image/pd1.png") left center no-repeat;
            background-size: 0.28rem auto;
            color: #1c83ea;
        }
        .order_list ul li .active_btn .no_btn em.msg{
            background: url("../image/pd2.png") left center no-repeat;
            background-size: 0.3rem auto;
            color: #f3a536;
        }
    </style>
</head>
<body>
<div id='secHeader'>
  <header class="header">
      <a href="javascript:void(0);" onclick="api.closeWin()" class="back_btn"><img src="../image/head-fanhui.png" alt=""></a>
      <h2 id='title'>电话咨询</h2>
      <!--<a href="javascript:void (0);" class="search_btn charge_btn">说明</a>-->
  </header>
</div>

<section class="picture_kinds">
    <div class="news_kinds">
        <ul>
            <li class="active"><a href="javascript:;">全部订单</a></li>
            <li><a href="javascript:;" >未完成</a></li>
            <li><a href="javascript:;" >已完成</a></li>
        </ul>
    </div>
</section>
<section class="order_section">
    <div class="order_list">
        <ul id='con'>
            <li>
                <p>订单号：2524556842</p>
                <div class="order_info">
                    <img src="../image/userimg2.jpg" alt="">
                    <div class="info">
                        <h6>方大同</h6>
                        <span>电话咨询</span>
                    </div>
                    <a href="##" class="look_demand">查看需求</a>
                </div>
                <div class="order_active">
                    <span>总计：<em>¥30.00</em></span>
                    <div class="active_btn">
                        <a href="##" class="no_btn">拒绝接单</a>
                        <a href="##" class="yes_btn">确认拨打</a>
                    </div>
                </div>
            </li>

        </ul>
    </div>
</section>


</body>

<script>
    var page=1;
    var para='';
    var state=0;
    var title='';
    var type

    apiready = function () {
      $api.fixStatusBar( $api.dom('#secHeader') );
      api.setStatusBarStyle({
          style: 'light'
      });

        api. addEventListener({name:'scrolltobottom'}, function(ret, err){

            toDoRequest();

        });

        //下拉刷新
        api.setRefreshHeaderInfo({
          visible: true,
          bgColor: 'rgba(255,255,255,255)',
          textColor: '#666',
          textDown: '下拉刷新',
          textUp: '释放刷新'
        }, function(ret, err) {
          toDoRefresh();
        });

        para=api.pageParam;

        type=para.type
        if(para.type==1){
            title='图文咨询';
            $('#title').html('图文咨询');
        }else if(para.type==2){
            title='电话咨询';
            $('#title').html('电话咨询');
        }else if(para.type==3){
            title='见面咨询';
            $('#title').html('见面咨询');
        }else if(para.type==4){
            title='代写文书';
            $('#title').html('代写文书');
        }else if(para.type==5){
            title='律师函';
            $('#title').html('代发律师函');
        }

        toDoRequest()
    };

    //跳转留言
    function message(id,orderno) {
        api.openWin({
            name: 'viewmessage',
            url: './viewmessage.html',
            reload:true,
            pageParam: {
                id: id,
                orderno: orderno
            }
        });
    }

    function toDoRequest(){
        if(!loginCheck()){
            return;
        }
        var p= {token:token,type:para.type,state:state,page:page};
        //alert(JSON.stringify(p))
        api.ajax({
                url: webSiteUrl+'/app/user/saskorder',
                method: 'post',
                data: {
                    values: p
                }
            }, function(ret, err) {
                api.hideProgress();

                if(ret.code==200){

                    html = "";
                    var tj=ret.data;
                    if(tj != null){

for(var i=0;i<tj.length;i++){
                        if(ck(tj[i].icon)){
                            var u=''
                        }else{
                            var u=webSiteUrl
                        }
html+='<li id="'+tj[i].id+'"><p>订单号：'+tj[i].orderno+'</p><div class="order_info" onclick="chakan(' + tj[i].id + ',' + tj[i].type + ')"><img src="'+u+tj[i].icon+'" alt=""><div class="info"><h6>'+tj[i].name+'</h6><span>'+title+'</span></div>';

                    if(tj[i].type==3 || tj[i].type==4|| tj[i].type==5){
                        html+= ' <a href="##" class="look_demand"  onclick="chakan('+tj[i].id+')">查看需求</a>';
                    }else if(tj[i].type==1 && tj[i].state==2){
                        html+= '<a href="##" class="look_demand1" onclick="message('+tj[i].id+','+tj[i].orderno+')">查看文件</a> <a href="##" class="look_demand" onclick="message('+tj[i].id+','+tj[i].orderno+')">上传文件</a>';
                    }
html+='</div><div class="order_active"><span>总计：<em>¥'+tj[i].money+'</em></span>';

                    if(tj[i].status==1){
html+='<div class="active_btn"><a href="##" class="no_btn" onclick="orderstatus('+tj[i].id+','+3+')">拒绝接单</a><a href="##" class="yes_btn" onclick="orderstatus('+tj[i].id+','+2+')">确认接单</a></div>';

                    }else if(tj[i].status==2){
                         if(para.type==2){
                            html+='<div class="active_btn"><a href="tel:'+tj[i].phone+'" class="no_btn" onclick="contactuser('+tj[i].uid+')" style="border: 1px #1c83ea solid;"><em class="tel">联系客户</em></a><a href="##" class="yes_btn" onclick="orderstatus('+tj[i].id+','+4+')">确认完成</a></div>';
                        }else if(para.type==1){
                            html+='<div class="active_btn"><a href="tel:'+tj[i].phone+'" class="no_btn" onclick="contactuser('+tj[i].uid+')" style="border: 1px #f3a536 solid;"><em class="msg">联系客户</em></a><a href="##" class="yes_btn" onclick="orderstatus('+tj[i].id+','+4+')">确认完成</a></div>';
                        }else{
                            html+='<div class="active_btn"><a href="tel:'+tj[i].phone+'" class="no_btn" onclick="contactuser('+tj[i].uid+')" style="border: 1px #1c83ea solid;">联系客户</a><a href="##" class="yes_btn" onclick="orderstatus('+tj[i].id+','+4+')">确认完成</a></div>';
                        }

                    }else{
                        html+='<div class="active_btn">已完成</div>';
                        /*if(tj[i].uover==0){
                            html+='<div class="active_btn">等待客户确认完成</div>';
                        }else if(tj[i].uover==1){
                            html+='<div class="active_btn">客户已确认完成</div>';
                        }else if(0){

                        }*/
                    }
html+='</div></div></li>';
}

                    }
                    if(page==1){
                        $('#con').html(html);
                    }else{
                        $('#con').append(html);
                    }
                    page++;


                }else{
                    if(page==1){
                        $('#con').html('<p style="text-align:center">暂无数据</p>');
                    }

                }
            });

    }
    function chakan(id) {
        api.openWin({
            name: 'chakan',
            url: 'chakan.html',
            reload:true,
            pageParam: {
                id:id,
                type:1
            }
        });

    }
    function chuan(id,orderno) {
        api.openWin({
            name: 'chuan',
            url: 'chuan.html',
            reload:true,
            pageParam: {
                id:id,
                orderno:orderno
            }
        });

    }
    function checkfile(id){
        api.openWin({
            name: 'checkfile',
            url: 'checkfile.html',
            reload:true,
            pageParam: {
                id:id,

            }
        });


    }
    function contactuser(id) {

    }

    function orderstatus(id,num){
        if(num==2){
            var askmsg='确认接单吗？'
        }else if(num==3){
            var askmsg='确认拒接订单吗？'
        }else if(num==4){
            var askmsg='确认完成吗？'
        }else if(num==5){
            var $askmsg='确认吗？'
        }

        api.confirm( {
          title: '提示',
          msg: askmsg,
          buttons: [ '确定', '取消' ]
        }, function ( ret, err ) {
           var index = ret.buttonIndex;

           if ( index == 1 ) {
                var p={token:token,status:num,id:id}
                api.ajax({
                    url: webSiteUrl+'/app/user/askorderstatus',
                    method: 'post',
                    data: {
                        values:p
                    }
                }, function(ret, err) {
                    if(ret.code==200){

                        $('#'+id).remove();

                    }
                });
            }

        })
    };



    $(document).on('click','.news_kinds li',function(){
        $(this).addClass('active').siblings().removeClass('active');

        page=1
        state=parseInt($(this).index()+1);
        if(state==1){
            state=0
        }
        toDoRequest();
    });


</script>
</html>
